package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import java.lang.reflect.Proxy;

import beiwanglu.MementoMana;
import beiwanglu.Game;
import beiwanglu.Memento;
import daili.Domestic;
import daili.DynamicProxy;
import daili.People;
import fangwenzhe.Busy;
import fangwenzhe.Idler;
import fangwenzhe.Music;
import fangwenzhe.Video;
import fangwenzhe.Visitor;
import fangwenzhe.Websites;
import jiexiqi.Calculator;
import mingling.Command;
import mingling.Invoker;
import mingling.Receiver;
import mingling.ShutdownCommand;
//import qiaojie.Clothes;
import qiaojie.Clothes;
import qiaojie.Coder;
import qiaojie.Person;
import qiaojie.Shirt;
import qiaojie.Student;
import qiaojie.Uniform;
import shipeiqi.Adapters;
import shipeiqi.Electric;
import shipeiqi.PhoneAdapter;
import xiangyuan.BikeFactory;
import xiangyuan.IBike;
import zhongjie.Landlord;
import zhongjie.Lianjia;
import zhongjie.Purchaser;
import zhuangshizhe.Bedroom;
import zhuangshizhe.Kitchen;
import zhuangshizhe.NewRoom;
import zhuangshizhe.Room;
import zhuangshizhe.RoomDecorator;
import zuhe.Column;
import zuhe.Content;
import zuhe.PageElement;
//import celuo.MyContext;
//import guangchazhe.Postman;
//import zerenlian.Postman;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //builder模式
//        Computer computer=new Computer.Buider("Intel","显示器","华硕主板").keys("飞燕键盘").shubiao("双飞燕").build();
//        System.out.println("输出的是"+computer.toString());//打印
        //外观模式
//        Manager manager=new Manager();
//        manager.logins();
//        manager.toMain();
        //单例模式
//        Singleton.getInstance().doSomething();

        //简单工厂模式
//        NokiaFactory nokiaFactory = new NokiaFactory();
//        Nokia5200 nokia5200 = nokiaFactory.createNokia(Nokia5200.class);
//        NokiaN97 nokiaN97 = nokiaFactory.createNokia(NokiaN97.class);
//        nokia5200.openPhone();
//        nokiaN97.openPhone();

        //抽象工厂模式
//        Hardware macFactory = new MacFactory();
//        Keyboard keyboard = macFactory.createKyeBoard();
//        keyboard.input();//Mac 专用键盘
//
//        Hardware winFactory = new WinFactory();
//        Mouse mouse = winFactory.createMouse();
//        mouse.click();  //win 专用鼠标
        //原型模式
//        Person person = new Person();
//        person.setName("小明");
//        Action action = new Action();
//        action.setActionType("吃饭");
//        ArrayList<String> listStr = new ArrayList<>();
//        listStr.add("好的");
//        person.setAction(action);
//        person.setListStr(listStr);
//        Log.e("*******","---------原person---------");
//        Log.e("*******",person.toString());
//
//        //clone(克隆)一份后
//        Person p = (Person) person.clone();//拷贝一个对象
//        p.getAction().setActionType("睡觉");
//        p.getListStr().add("不要");
//
//        Log.e("*******","---------clone的person---------");
//        Log.e("*******",p.toString());
//        Log.e("*******","---------原person---------");
//        Log.e("*******",person.toString());//原来的数据没有改变
        //策略模式
//        MyContext context;
//        context=new MyContext(new ShoppingStrategy());
//        context.chase();
//        context=new MyContext(new MoviesStrategy());
//        context.chase();
//        context=new MyContext(new EattingStrategy());
//        context.chase();
       //状态模式
//        MyContext context = new MyContext(new LoveState());
//        context.shopping();
//        context.movies();
//
//        MyContext context1 = new MyContext(new DogState());
//        context1.shopping();
//        context1.movies();

        //责任链模式
//        //创建不同的快递员对象
//        Postman beijingPostman = new BeijingPostman();
//        Postman shanghaiPostman = new ShanghaiPostman();
//        Postman guangzhouPostman = new GuangzhouPostman();
//        //创建下一个结点
//        beijingPostman.nextPostman=shanghaiPostman;//北京快递  上海快递  广州快递
//        shanghaiPostman.nextPostman=guangzhouPostman;
//        //处理不同地区的快递，都是从首结点北京快递员开始
//        Log.e("***"," 有一个上海快递需要派送 ");
//        beijingPostman.handleCourier("Shanghai");
//        Log.e("***"," 有一个广州快递需要派送 ");
//        beijingPostman.handleCourier("Guangzhou");
          //观察者模式
//        Observable postman=new Postman();
//        Observer boy1=new Boy("路飞");
//        Observer boy2=new Boy("乔巴");
//        Observer girl1=new Girl("娜美");
//        postman.add(boy1);
//        postman.add(boy2);
//        postman.add(girl1);
//        postman.notify("快递到了,请下楼领取.");
        //模板模式
//        System.out.println("----派送A----");
//        Postman postA=new PostA();
//        postA.post();
//        System.out.println("----派送B----");
//        Postman postB=new PostB();
//        postB.post();

          //迭代器模式
//        Aggregate aggregate=new DeliveryAggregate();
//        aggregate.add("1111");
//        aggregate.add("2222");
//        aggregate.add("3333");
//        aggregate.add("9527");
//
//        Iterator iterator = aggregate.iterator();
//        while (iterator.hasNext()){
//            String tel = (String) iterator.next();
//            System.out.println("当前号码为："+tel);
//        }
//        System.out.println("后面没有了");

//        //备忘录模式
//        System.out.println("首次进入游戏");
//        Game game = new Game();
//        game.play();//玩游戏
//        Memento memento = game.createMemento();//创建存档
//        MementoMana caretaker = new MementoMana();
//        caretaker.setMemento(memento);//保存存档
//        game.exit();//退出游戏
//        System.out.println("-------------");
//        System.out.println("二次进入游戏");
//        Game secondGame = new Game();
//        secondGame.setMemento(caretaker.getMemento());//读取存档
//        secondGame.play();//继续玩游戏
//        secondGame.exit();//不存档,嘿嘿嘿

        //访问者模式
//        //创建不同的受访问者
//        Music wangyiyue = new Music("网易云音乐");
//        Music kugou = new Music("酷狗");
//        Video youku = new Video("优酷");
//        Video iqiyi = new Video("爱奇艺");
//        //放入受访问者管理类中
//        Websites websites = new Websites();
//        websites.addWeb(wangyiyue);
//        websites.addWeb(kugou);
//        websites.addWeb(youku);
//        websites.addWeb(iqiyi);
//        //访问者
//        Visitor idler1 = new Idler("闲人1号");
//        websites.accept(idler1);//集合接受idler1的访问 访问者去访问受访问者
//
//        System.out.println("-------------------------------------");
//        Visitor busy1 = new Busy("忙人2号");
//        websites.accept(busy1);////集合接受busy1的访问

//          //中介者模式
//        Lianjia houseMediator = new Lianjia();
//        Purchaser purchaser = new Purchaser(houseMediator);
//        Landlord landlord = new Landlord(houseMediator);
//        houseMediator.setLandlord(landlord);
//        houseMediator.setPurchaser(purchaser);
//
//        landlord.send("出售一套别墅");
//        System.out.println("------------------------");
//        purchaser.send("求购一套学区房");

//        //解析器模式
//        Calculator calculator = new Calculator();
//        calculator.read("a = 1024");//读取表达式
//        calculator.read("b = 512");
//        System.out.println("a = 1024");
//        System.out.println("b = 512");
//
//        calculator.read("a + b");
//        System.out.println("a + b = " + calculator.calculate());//计算结果
//        calculator.read("a - b");
//        System.out.println("a - b = " + calculator.calculate());

//        //命令模式
//        Receiver receiver = new Receiver();//创建命令接收者
//        Command command = new ShutdownCommand(receiver);//创建一个命令的具体实现对象，并指定命令接收者
//        Invoker invoker = new Invoker(command);//创建一个命令调用者，并指定具体命令
//        invoker.action();//发起调用命令请求

//        //代理模式 动态代理
//        People domestic = new Domestic(); //创建国内购买人 真实主题类
//        DynamicProxy proxys = new DynamicProxy(domestic); //创建动态代理
//        ClassLoader classLoader = domestic.getClass().getClassLoader(); //获取ClassLoader
//        People oversea = (People) Proxy.newProxyInstance(classLoader, new Class[]{People.class}, proxys); //通过 Proxy 创建海外代购实例 ，实际上通过反射来实现的。
//        oversea.buy();//调用海外代购的buy()

        //组合模式
        //依赖具体的实现类Column
//        Column root = new Column("网站页面");
//        Column music = new Column("音乐");
//        Column video = new Column("视屏");
//        PageElement ad = new Content("广告");
//        root.addPageElement(music);
//        root.addPageElement(video);
//        root.addPageElement(ad);
//        Column chineseMusic = new Column("国语");
//        Column cantoneseMusic = new Column("粤语");
//        music.addPageElement(chineseMusic);
//        music.addPageElement(cantoneseMusic);
//        chineseMusic.addPageElement(new Content("十年.mp3"));
//        cantoneseMusic.addPageElement(new Content("明年今日.mp3"));
//        video.addPageElement(new Content("唐伯虎点秋香.avi"));
//        root.print("");

        //适配器模式
//        Adapters phoneAdapter = new PhoneAdapter();
//        System.out.println("适配转换后的电压：" + phoneAdapter.convert_5v());

//        //装饰者模式
//        Room newRoom = new NewRoom();//有一间新房间
//        RoomDecorator bedroom = new Bedroom(newRoom);
//        bedroom.fitment();//装修成卧室
//        RoomDecorator kitchen = new Kitchen(newRoom);
//        kitchen.fitment();//装修成厨房

        //享元模式
//        BikeFactory factory=new BikeFactory();
//        IBike ofo = factory.getBike("ofo");
//        ofo.billing(2);
//        IBike mobike = factory.getBike("Mobike");
//        mobike.billing(1);
//        IBike ofo1 =  factory.getBike("ofo");
//        ofo1.billing(3);

        //桥接模式
        //创建各种衣服对象
        Clothes uniform = new Uniform();
        Clothes shirt = new Shirt();

        //不同职业的人穿衣服
        Person coder = new Coder();
        coder.setClothes(shirt);
        coder.dress();

        System.out.println("--------------------------------------");
        Person student = new Student();
        student.setClothes(uniform);
        student.dress();

        System.out.println("--------------------------------------");
        student.setClothes(shirt);
        student.dress();

    }
}